dynamic class com.c3d.mediaRotator.controllers.Controller extends Object
{
    var _controllerType: String = "base";
    var _modalOverlayVisible: Boolean = false;
    var _netLoadMarshall = null;
    var _externalConduit = null;
    var _panelTransitionManager = null;
    var _model;
    var _numberOfPanelsToLoad;
    var _panelControllers;
    var _panelsPending;
    var _rootLevel;
    var _view;

    function Controller($root_mc)
    {
        super();
        this._panelsPending = 0;
        this._numberOfPanelsToLoad = 0;
        this.attachEventListeners();
        this._rootLevel = $root_mc;
        this._model = new com.c3d.mediaRotator.data.Model();
        if (_root.feedSrc == undefined) 
        {
            this._model.__set__feedSrc("/flash/drone/xml/otdata.xml");
        }
        else 
        {
            this._model.__set__feedSrc(_root.feedSrc);
        }
        this._model.__set__feedType("xml");
        this._model.__set__controller(this);
        this._view = new com.c3d.mediaRotator.display.View(this, this._rootLevel);
        this.initializeExternalConduit();
        com.c3d.common.ui.mouse.MouseOutDetector.startup(this._rootLevel);
        com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.common.events.MVCEvent.CONTROLLER_INSTANTIATED, target: this});
        this.startup();
    }

    function startup()
    {
        this._model.initialize(true);
    }

    function initializeExternalConduit()
    {
        if (_root.comm_channel.substr(0, 5) == "comm_") 
        {
            this._externalConduit = new com.c3d.common.external.ExternalConduit(_root.comm_channel);
            return;
        }
        this._externalConduit = new com.c3d.common.external.ExternalConduit();
    }

    function attachEventListeners()
    {
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.common.events.ExternalEvent.INTERNAL_LEAVE_REQUEST, this.onLeaveRequest);
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.common.events.MVCEvent.VIEW_READY, mx.utils.Delegate.create(this, this.onViewReady));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.common.events.MVCEvent.MODEL_READY, mx.utils.Delegate.create(this, this.onModelReady));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.common.events.NetworkEvent.NETWORK_REQUEST_COMPLETE, mx.utils.Delegate.create(this, this.onNetworkRequestComplete));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.common.events.NetworkEvent.NETWORK_REQUEST_START, mx.utils.Delegate.create(this, this.onNetworkRequestStart));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.common.events.NetworkEvent.NETWORK_QUEUE_EMPTIED, mx.utils.Delegate.create(this, this.onNetworkRequestQueueEmpty));
        com.c3d.common.events.CentralDispatch.addEventListener("uiTabPress", mx.utils.Delegate.create(this, this.onTabPressEvent));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelEvent.PANEL_PRESS, mx.utils.Delegate.create(this, this.onPanelPressEvent));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelEvent.PANEL_RELEASE, mx.utils.Delegate.create(this, this.onPanelReleaseEvent));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelEvent.PANEL_ROLLOVER, mx.utils.Delegate.create(this, this.onPanelRolloverEvent));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelEvent.PANEL_ROLLOVER, mx.utils.Delegate.create(this, this.onPanelRolloutEvent));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_TRANSITION_BEGIN, mx.utils.Delegate.create(this, this.onPanelTransitionBegin));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_REQUESTED_TRANSITION_BEGIN, mx.utils.Delegate.create(this, this.onRequestedPanelTransitionBegin));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_TRANSITION_COMPLETE, mx.utils.Delegate.create(this, this.onPanelTransitionComplete));
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_REQUESTED_TRANSITION_COMPLETE, mx.utils.Delegate.create(this, this.onRequestedPanelTransitionComplete));
    }

    function requestNetworkData($src, $type)
    {
        if (this._netLoadMarshall == null) 
        {
            this._netLoadMarshall = new com.c3d.common.net.NetLoadMarshall();
        }
        var __reg2 = this._netLoadMarshall.requestLoad($src, $type);
        return __reg2;
    }

    function setupBaseControllers($pd)
    {
        var __reg4 = new Array();
        var __reg2 = 0;
        __reg2;
        while (__reg2 < $pd.length) 
        {
            ++this._panelsPending;
            __reg4.push(new com.c3d.mediaRotator.controllers.PanelController($pd[__reg2], this, this.__get__viewMovieClip()));
            ++__reg2;
        }
        return __reg4.concat();
    }

    function getCurrentPanelControllerIndex()
    {
        var __reg3 = -1;
        var __reg4 = this._panelTransitionManager.__get__currentPanel();
        var __reg2 = 0;
        while (__reg2 < this._panelControllers.length) 
        {
            if (__reg4 == this._panelControllers[__reg2].view.viewMovieClip) 
            {
                __reg3 = __reg2;
            }
            ++__reg2;
        }
        return __reg3;
    }

    function onPanelTransitionBegin($event)
    {
        var __reg3 = this._panelTransitionManager.__get__currentPanel();
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this._panelControllers.length) 
            {
                return;
            }
            if (__reg3 == this._panelControllers[__reg2].view.viewMovieClip) 
            {
                this._panelControllers[__reg2].activateView();
            }
            ++__reg2;
        }
    }

    function onRequestedPanelTransitionBegin($event)
    {
        var __reg3 = this._panelTransitionManager.__get__currentPanel();
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this._panelControllers.length) 
            {
                return;
            }
            if (__reg3 == this._panelControllers[__reg2].view.viewMovieClip) 
            {
                this._panelControllers[__reg2].activateView();
            }
            ++__reg2;
        }
    }

    function onPanelTransitionComplete($event)
    {
        var __reg3 = this._panelTransitionManager.__get__currentPanel();
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this._panelControllers.length) 
            {
                return;
            }
            if (__reg3 != this._panelControllers[__reg2].view.viewMovieClip) 
            {
                this._panelControllers[__reg2].deactivateView();
            }
            ++__reg2;
        }
    }

    function onRequestedPanelTransitionComplete($event)
    {
        var __reg3 = this._panelTransitionManager.__get__currentPanel();
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this._panelControllers.length) 
            {
                return;
            }
            if (__reg3 != this._panelControllers[__reg2].view.viewMovieClip) 
            {
                this._panelControllers[__reg2].deactivateView();
            }
            ++__reg2;
        }
    }

    function onNetworkRequestStart($event)
    {
        if ($event.loadtype == "BINARY") 
        {
            ++this._numberOfPanelsToLoad;
        }
    }

    function onNetworkRequestComplete($event)
    {
        if ($event.loadtype == "BINARY") 
        {
            --this._numberOfPanelsToLoad;
            !(this._numberOfPanelsToLoad == 0 && this._panelTransitionManager == null);
            return;
        }
    }

    function onNetworkRequestQueueEmpty($event)
    {
    }

    function onModelReady($event)
    {
        this._view.render();
        this._panelControllers = new Array();
        this._panelControllers = this.setupBaseControllers(this._model.__get__panelData());
    }

    function onViewReady($event)
    {
    }

    function onPanelPressEvent($event)
    {
        if ($event.urlRequest.href.charAt(0) == ":") 
        {
            var __reg3 = $event.urlRequest.href.split(":");
            var __reg2 = 0;
            while (__reg3[__reg2].length == 0) 
            {
                ++__reg2;
            }
            var __reg5 = __reg3[__reg2];
            if ((__reg0 = __reg5.toLowerCase()) === "video") 
            {
                this.launchVideoPanel({href: __reg3[__reg2 + 1]});
            }
            return;
        }
        if (com.c3d.common.utils.URLTool.isValid($event.urlRequest.href, true)) 
        {
            this.onLeaveRequest($event.urlRequest.href, $event.urlRequest.target);
            return;
        }
    }

    function onPanelReleaseEvent($event)
    {
    }

    function onPanelRolloverEvent($event)
    {
    }

    function onPanelRolloutEvent($event)
    {
    }

    function onTabPressEvent($event)
    {
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this._panelControllers.length) 
            {
                return;
            }
            if ($event.controller == this._panelControllers[__reg2]) 
            {
                this.requestSeekToPanel(__reg2);
            }
            ++__reg2;
        }
    }

    function onTabReleaseEvent($event)
    {
    }

    function requestSeekToPanel($targetPanelControllerIndex)
    {
        this._panelTransitionManager.requestTransitionToPanel(this._panelControllers[$targetPanelControllerIndex].view.viewMovieClip);
    }

    function launchVideoPanel($urlRequest)
    {
        if (com.c3d.common.utils.URLTool.isValid($urlRequest.href, true)) 
        {
            com.c3d.common.external.ExternalConduit.callJavascript("externalConduit", "", {action: "launchExternalSubview", src: $urlRequest.href});
            this._panelTransitionManager.stop();
            this.startModalDim();
        }
    }

    function hideVideoPanel()
    {
        this._panelTransitionManager.start();
        com.c3d.common.external.ExternalConduit.callJavascript("externalConduit", "", {action: "hideExternalSubview"});
        this.endModalDim();
    }

    function onVideoPlayerClose($event)
    {
    }

    function startModalDim()
    {
        this._modalOverlayVisible = true;
        this._view.requestModalDimStart();
        this._panelTransitionManager.pausePlayback();
        this._view.__get__viewRoot().onRelease = mx.utils.Delegate.create(this, this.onModalDimButtonPress);
        com.c3d.common.events.CentralDispatch.addEventListener("modalDimButtonPress", mx.utils.Delegate.create(this, this.onModalDimButtonPress));
    }

    function endModalDim()
    {
        this._modalOverlayVisible = false;
        this._view.requestModalDimEnd();
        this._panelTransitionManager.resumePlayback();
        delete this._view.__get__viewRoot().onRelease;
    }

    function onModalDimButtonPress($event)
    {
        this.hideVideoPanel();
    }

    function onLeaveRequest($href, $target)
    {
        this._externalConduit.leave($href, $target);
    }

    function childControllerReady($pc)
    {
        --this._panelsPending;
        if (this._panelsPending <= 0) 
        {
            setTimeout(mx.utils.Delegate.create(this, this.revealStage), 200);
        }
    }

    function get bannerGlobalConfigParams()
    {
        return this._model.__get__globalConfigParams();
    }

    function get transitionParameters()
    {
        var __reg2 = new Object();
        __reg2.duration = this._model.bannerTransitionDuration;
        __reg2.mouseMoveTimeout = this._model.mouseMoveTimeout;
        var __reg3 = this.getCurrentPanelControllerIndex() < 0 ? this._panelControllers.length - 1 : this.getCurrentPanelControllerIndex();
        __reg2.delay = this._panelControllers[__reg3].panelTransitionDelay;
        return __reg2;
    }

    function get modalOverlayVisible()
    {
        return this._modalOverlayVisible;
    }

    function get view()
    {
        return this._view;
    }

    function get viewMovieClip()
    {
        return this._view.__get__viewMovieClip();
    }

    function get controllerType()
    {
        return this._controllerType;
    }

    function get currentBasePanelSprites()
    {
        var __reg2 = new Array();
        for (var __reg3 in this._panelControllers) 
        {
            __reg2.push(this._panelControllers[__reg3].view.viewMovieClip);
        }
        return __reg2.concat();
    }

    function get currentPanelModels()
    {
        var __reg3 = new Array();
        var __reg2 = 0;
        while (__reg2 < this._panelControllers.length) 
        {
            __reg3.push(this._panelControllers[__reg2].panelModelData);
            ++__reg2;
        }
        return __reg3;
    }

    function get panelTabInfo()
    {
        var __reg5 = new Array();
        for (var __reg6 in this._panelControllers) 
        {
            __reg5.push(new Object({label: this._panelControllers[__reg6].navButtonInformation.label, id: __reg6, controller: this._panelControllers[__reg6]}));
        }
        return __reg5;
    }

    function revealStage()
    {
        this._panelTransitionManager = new com.c3d.mediaRotator.transitions.PanelTransitionManager(this.__get__currentBasePanelSprites().concat(), this);
        this._panelTransitionManager.start();
        this.__get__viewMovieClip()._visible = true;
        this._view.requestHideLoaderScreen();
    }

}
